home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / PowerMacOr68K / Source / PowerMacOr68K.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  2.1 KB  |  78 lines  |  [TEXT/CWIE]

  1. /****
  2.     This snippet shows how to determine whether you are running on
  3.     a Power Macintosh or on a 680x0 Macintosh.  It also provides the
  4.     method for determine exactly which type of processor is running.
  5.     This works around an off-by-one error with gestaltNativeCPUType.
  6.     
  7.     Written by Virginia (Ginny) McCulloh
  8.     Apple Developer Technical Support
  9.     August 1995, Cupertino, CA
  10.     Copyright 1995, Apple Computer, Inc.
  11.  
  12.     This runs under Think C 7.0.4, CodeWarrior 6,
  13.      and MPW 3.3.1 with the Universal Headers.
  14. ****/
  15.  
  16.  
  17. #include <Gestalt.h>
  18. #include <stdio.h>
  19.  
  20. Boolean    hasPowerPCArch(void);
  21.  
  22. void main()
  23. {
  24.     OSErr    err;
  25.     long    feature;
  26.  
  27.     /* First we will check the system architecture. */
  28.     if (hasPowerPCArch())    /* It's a Power Macintosh of some sort */
  29.     {
  30.         /* What kind of Power Macintosh processor is this. */
  31.         err = Gestalt (gestaltNativeCPUtype, &feature);
  32.         if (0x100 & feature)    
  33.         {
  34.             if (gestaltCPU601 == feature)
  35.                 printf( "\nThis puppy is a PowerMac with a 601 processor!");
  36.             else if (gestaltCPU603 == feature)
  37.                 printf( "\nThis puppy is a PowerMac with a 603 processor!");
  38.             else if (gestaltCPU604 == feature)
  39.                 printf( "\nThis puppy is a PowerMac with a 604 processor!");
  40.             else
  41.                 printf( "\nThis must be some sort of PowerMac.  I think.");
  42.         }
  43.     }
  44.     else                    /* This is some sort of 68K machine */
  45.     {
  46.         err = Gestalt ( gestaltProcessorType, &feature );
  47.         if (gestalt68040 == feature)
  48.             printf( "\nThis is a 68040." );
  49.         else if (gestalt68030 == feature)
  50.             printf( "\nThis is a 68030.");
  51.         else if (gestalt68020 == feature)
  52.             printf( "\nThis is a 68020.");
  53.         else if (gestalt68010 == feature)
  54.             printf( "\nThis is a 68010.");
  55.         else if (gestalt68000 == feature)
  56.             printf( "\nThis is a 68000.");
  57.         else
  58.             printf( "\nI don't know what this is.");
  59.         
  60.     }
  61. }
  62.  
  63. Boolean    hasPowerPCArch()
  64. /* 
  65.     Gestalt will return an error if the gestaltSysArchitecture selector is
  66.     not recognized by the System, so we can assume this is a 68K machine.
  67.     Otherwise, this function returns true for a Power Mac and false for
  68.     a 68K Mac.
  69. */
  70. {
  71.     long    gestaltResult;
  72.  
  73.     if (Gestalt(gestaltSysArchitecture, &gestaltResult))
  74.         return(false);
  75.     else
  76.         return(gestaltResult == gestaltPowerPC);
  77. }
  78.